package com.scn.base.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import net.sf.json.JSONObject;
import com.scn.base.dao.impl.DAOManager;
import com.scn.base.domain.RolePowerVO;
import com.scn.base.domain.RoleVO;
import com.scn.base.page.PageVO;
import com.scn.base.service.ISysRoleService;
@Service("sysRoleService")
public class SysRoleServiceImpl implements ISysRoleService{
	@Autowired
	private DAOManager daoManager;
	public int selectRoleCount() {
		return daoManager.getSysRoleDao().selectRoleCount();
	}
	public void insertSysRole(RoleVO role) {
		daoManager.getSysRoleDao().insertSysRole(role);
	}
	public String selectRoleForSelect() {
		List alist=daoManager.getSysRoleDao().selectRoleList();
		if(alist==null){
			return "";
		}
		JSONObject jo= new JSONObject();
		for(Object o:alist){
			RoleVO role=(RoleVO)o;
			jo.put(role.getId()+"", role.getName());
		}
		return jo.toString();
	}
	public List selectRoleList(PageVO page) {
		return daoManager.getSysRoleDao().selectRoleList(page);
	}
	public void saveSysRoles(String srname,String srdesc,String srpname) {
		int srid=Integer.parseInt(srpname);
		long roleId=daoManager.getSysRoleDao().getSeq();
		RoleVO role=new RoleVO();
        role.setId(roleId);
		role.setName(srname);
 		role.setDesc(srdesc);
 		//插入角色表
		daoManager.getSysRoleDao().insertSysRoles(role);
		// 获取复制组权限
		List<RolePowerVO> powerList=daoManager.getSysRolePowerDao().selectRolePowerBySrIdList(srid);
		if(powerList==null||powerList.size()==0){
			return;
		}
		for(Object o:powerList){
			RolePowerVO rolePower=(RolePowerVO)o;
			rolePower.setSrid(srid);
			// 插入新角色权限
			daoManager.getSysRolePowerDao().insertRolePower((rolePower));;
		}
	}
	public long getSeq() {
		return daoManager.getSysRoleDao().getSeq();
	}
	public void deleteSysRoleById(int srid) {
		daoManager.getSysRoleDao().deleteSysRoleById(srid);
	}
	public RoleVO selectRoleById(int srid) {
		return daoManager.getSysRoleDao().selectRoleById(srid);
	}
	public void updateSysRole(Map sysRoleMap) {
		daoManager.getSysRoleDao().updateSysRole(sysRoleMap);
	}
	public void saveSysRole(String srname, String srdesc, String srpname) {
		// TODO Auto-generated method stub
		
	}
	
}
